for  (let element  in sysposttype) {
    ele = `<option value="`+(sysposttype[element].english)+`" id="select-`+sysposttype[element].english+`">`+sysposttype[element].chinese+`</option>`
    document.getElementById("type_select").innerHTML += ele
}
window.onload = function() {
    if (pid == 0) {
        v.setValue("")
        return
    }
    // 开局加载文章信息
    $.get("/post/api/get/info",{
        pid:pid
    },function(data) {
        if (data.msg != undefined) {
            error_bar(data.msg)
            return
        }
        document.getElementById("title").value = data.title
        document.getElementById("type_select").value = data.type
        $("option:selected").attr("selected", false);
        $("#select-"+data.type).attr("selected",true);
        document.getElementsByClassName("mdui-select mdui-select-position-auto")[0].style.display = 'none'
        var inst = new mdui.Select("#type_select");
        inst.handleUpdate()
    })
    $.get("/post/api/get/content",{
        pid:pid
    },function(data) {
        if (data.msg != undefined) {
            error_bar(data.msg)
            return
        }
        v.setValue(data)
    })
}

function onSaveBtn() {
    if (pid == 0) {
        ask_bar("确认上传吗？",save)
    } else {
        ask_bar("确定更新吗？（原来的内容不保存哦）",save)
    }
}

function save() {
    var flag = false
    $.post("/post/api/post/"+pid+"/info", {
        title: document.getElementById("title").value,
        type: document.getElementById("type_select").value
    },function(data) {
        if (data.code != 0) {
            error_bar(data.msg)
            return
        }
        $.post("/post/api/post/"+data.pid+"/content", {
            content: v.getValue()
        },function(data) {
            if (data.code != 0) {
                error_bar(data.msg)
                return
            }
            success_bar("更新成功")
        })
    })
    
}